package com.xy.farm.activity.deal;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;

import com.xy.farm.R;
import com.xy.farm.activity.adapter.PageAdapter;
import com.xy.farm.activity.base.BaseActivity;
import com.xy.farm.activity.deal.adapter.SearchGoodsAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 1174607250 on 2018/8/16.
 */

public class SearchActivity extends BaseActivity
{
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private PageAdapter adapter;
    private RecyclerView recyclerView1;
    private RecyclerView recyclerView2;
    private SearchGoodsAdapter goodsAdapter;
    private List<View> views = new ArrayList<>();
    private List<String> strings = new ArrayList<>();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);
        findViewById(R.id.btn_back).setOnClickListener(this);
        tabLayout = findViewById(R.id.tabLayout);
        viewPager = findViewById(R.id.viewPager);
        strings.add("商品");
        strings.add("动态");
        views.add(LayoutInflater.from(this).inflate(R.layout.layout_search, null));
        views.add(LayoutInflater.from(this).inflate(R.layout.layout_search, null));
        recyclerView1 = views.get(0).findViewById(R.id.recyclerView);
        recyclerView2 = views.get(1).findViewById(R.id.recyclerView);
        viewPager.setAdapter((adapter = new PageAdapter(views, strings)));
        tabLayout.setupWithViewPager(viewPager);
        tabLayout.setTabsFromPagerAdapter(adapter);

        recyclerView1.setHasFixedSize(true);
        recyclerView2.setHasFixedSize(true);
        StaggeredGridLayoutManager manager1 = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        recyclerView1.setLayoutManager(manager1);
        recyclerView1.setAdapter((goodsAdapter = new SearchGoodsAdapter()));

    }
}
